<template>
  <el-form :model="registerForm" ref="registerForm" label-width="100px" class="demo-ruleForm">
    <el-form-item label="用户id" prop="userId">
      <el-input v-model="registerForm.userId"></el-input>
    </el-form-item>
    <el-form-item label="用户名" prop="userName">
      <el-input v-model="registerForm.userName"></el-input>
    </el-form-item>
    <el-form-item label="用户密码" prop="userPassword">
      <el-input v-model="registerForm.userPassword"></el-input>
    </el-form-item>
    <el-form-item label="用户手机" prop="userTelephone">
      <el-input v-model="registerForm.userTelephone"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="submitForm('registerForm', registerForm)">
        立即创建</el-button>
      <el-button @click="resetForm('registerForm')">重置</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
export default {
  name: 'FundRegister',
  data () {
    return {
      isUpdate: '',
      registerForm: {
        userId: '',
        userName: '',
        userPassword: '',
        userTeleplone: ''
      }
    }
  },
  methods: {
    submitForm (formName, registerForm) {
      console.log(registerForm)
      this.$refs[formName].validate((valid) => {
        if (valid) {
          // alert('submit!');
          this.$axios
            .post('/fund/user/register', {
              userId: this.registerForm.userId,
              userName: this.registerForm.userName,
              userPassword: this.registerForm.userPassword,
              userTelephone: this.registerForm.userTelephone
            })
            .then(successResponse => {
              if (successResponse.data.code === 0) {
                this.$message({
                  message: '注册成功',
                  type: 'success'
                })
                this.$router.push({path: '/login'})
              } else {
                this.$message({
                  type: 'error',
                  message: this.bizresponse.message
                })
              }
            })
            .catch(failResponse => {
              this.$message({
                message: '注册失败，请重新添加',
                type: 'error'
              })
              this.resetForm('registerForm')
            })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    resetForm (formName) {
      this.$refs[formName].resetFields()
    }
  }
}
</script>

<style scoped>

</style>
